INSERT INTO  TRASPARENZA
SELECT * FROM (
 select 'T34',CODICE_BOLLETTA AS BOLLETTA,'','Sconto dipendente o pensionato ENEL','' AS DAL,'' AS AL
,0 AS GIORNI,0 SCAGLIONE,0 FASCIA,
0 CORR_UNIT,0 AS QUANTITA,
-B.TOTALE_BOLLETTA+competenze.totale_i AS TOTALE,'' ALI_IVA,null


FROM DB5.COMPETENZE@pgu3,(select distinct codice_bolletta,dip_enel from TMPMARKI) A,
    
    (SELECT BOLLETTA,SUM(TOTALE) TOTALE_BOLLETTA FROM TRASPARENZA WHERE RIGA IN ('T26','T30') GROUP BY BOLLETTA) B
WHERE
DB5.COMPETENZE.CODICE_COMPETENZA = A.CODICE_BOLLETTA
AND DB5.COMPETENZE.CODICE_GESTIONE ='UNRG'
AND DB5.COMPETENZE.CODICE_ORIGINE_COMPETENZA='B'
AND B.BOLLETTA = A.CODICE_BOLLETTA
AND A.DIP_ENEL IS NOT NULL )



